package com.liam.forum.controller;

import com.liam.forum.common.AppResult;
import com.liam.forum.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: LiamLMK
 * @CreateTime: 2024-09-06
 * @Description: to test controller
 * @Version: 1.0
 */
@Api(tags = "测试类的相关接口")
// Indicates that the result returned is data
@RestController
// Define 1st-level mapping path
@RequestMapping("/test")
public class TestController {

    @ApiOperation(("测试接口1, 显示你好springboot"))
    @GetMapping("/hello")
    public String hello() {
        return "Hello, Springboot!";
    }


    @ApiOperation(("测试接口4, 按传入name显示你好信息"))
    @PostMapping("/helloByName")
    public AppResult helloByName(@ApiParam("姓名") @RequestParam("name") String name) {
        return AppResult.success("hello, " + name);
    }


    @ApiOperation(("测试接口2, 显示抛出的异常信息"))
    @GetMapping("/exception")
    public AppResult testException() throws Exception {
        throw new Exception("这是一个Exception...");
    }

    @ApiOperation(("测试接口3, 显示自定义异常信息"))
    @GetMapping("/appException")
    public AppResult testApplicationException() {
        throw new ApplicationException("这是一个ApplicationException...");
    }
}
